#pragma once

#include <mutex>
#include <memory>
#include "log/formatter/log_formatter.h"

namespace xlog {

struct log_msg;

/**
 * @brief 日志接收器接口
 */
class log_sink
{
public:
    virtual void sink(log_msg msg) = 0;
    virtual void flush() = 0;
public:
    //using ptr = std::shared_ptr<log_sink>;
protected:
    log_sink() {}
    ~log_sink() {}
private:
    log_sink(const log_sink &that) = delete;
    log_sink(log_sink &&that) = delete;
    log_sink &operator=(const log_sink &that) = delete;
    log_sink &operator=(log_sink &&that) = delete;
};

/**
 * @brief 日志接收器
 */
template<typename Mutex>
class log_sink_base : public log_sink
{
public:
    void sink(log_msg msg) final;
    void flush() final {}
protected:
    virtual void sink_it(log_msg msg) = 0;
    virtual void flush_it() = 0;
protected:
    std::unique_ptr<log_formatter> m_formatter;
    Mutex m_mutex;
};

}

#ifdef XLOG_HEADER_ONLY
#include "log_sink_base_inl.h"
#endif